<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitealbum
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: Controller.php 2011-08-026 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Sitealbum_Widget_FeaturedAlbumsController extends Engine_Content_Widget_Abstract {

  public function indexAction() {
    // List of featured album
    $table = Engine_Api::_()->getItemTable('album');
    $select = $table->select()
                    ->where('search = ?', true)
                    ->where("featured = ?", 1)
                    ->order("Rand()");

    $this->view->paginator = $paginator = Zend_Paginator::factory($select);
    // Set item count per page and current page number
    $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 4));
    $paginator->setCurrentPageNumber($this->_getParam('page', 1));
		$getFeaturedView = Zend_Registry::isRegistered('sitealbum_featuredview') ? Zend_Registry::get('sitealbum_featuredview') : null;
		$featuredAlbum = Engine_Api::_()->getApi('settings', 'core')->getSetting('sitealbum.featuredalbum', null);

    // Do not render if nothing to show
    if (($paginator->getTotalItemCount() <= 0) || empty($featuredAlbum) || empty($getFeaturedView) ) {
      return $this->setNoRender();
    }
  }

}
?>